/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bio.jpa.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Diego
 */
@Entity
@Table(name = "feature_key", catalog = "biodb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "FeatureKey.findAll", query = "SELECT f FROM FeatureKey f"),
    @NamedQuery(name = "FeatureKey.findByIdFeatureKey", query = "SELECT f FROM FeatureKey f WHERE f.idFeatureKey = :idFeatureKey"),
    @NamedQuery(name = "FeatureKey.findByName", query = "SELECT f FROM FeatureKey f WHERE f.name = :name"),
    @NamedQuery(name = "FeatureKey.findBySeq", query = "SELECT f FROM FeatureKey f WHERE f.seq = :seq")})
public class FeatureKey implements Serializable, Comparable<FeatureKey> {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Basic(optional = false)
    @Column(name = "id_feature_key")
    private Integer idFeatureKey;
    @Size(max = 45)
    @Column(name = "name")
    private String name;
    @Lob
    @Size(max = 16777215)
    @Column(name = "value")
    private String value;
    @Column(name = "seq")
    private Integer seq;
    @JoinColumn(name = "status_sts_id", referencedColumnName = "sts_id")
    @ManyToOne(optional = false)
    private Status statusStsId;
    @JoinColumn(name = "feature_fk", referencedColumnName = "id_feature")
    @ManyToOne(optional = false)
    private Feature featureFk;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "keyFk")
    private List<Qualifier> qualifierList = new ArrayList<Qualifier>();

    public FeatureKey() {
    }

    public FeatureKey(String name, String value, Integer seq, Feature featureFk) {
        this.name = name;
        this.value = value;
        this.seq = seq;
        this.featureFk = featureFk;
        statusStsId = new Status();
        statusStsId.setStsId(1);
    }

    public Integer getIdFeatureKey() {
        return idFeatureKey;
    }

    public void setIdFeatureKey(Integer idFeatureKey) {
        this.idFeatureKey = idFeatureKey;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Integer getSeq() {
        return seq;
    }

    public void setSeq(Integer seq) {
        this.seq = seq;
    }

    public Status getStatusStsId() {
        return statusStsId;
    }

    public void setStatusStsId(Status statusStsId) {
        this.statusStsId = statusStsId;
    }

    public Feature getFeatureFk() {
        return featureFk;
    }

    public void setFeatureFk(Feature featureFk) {
        this.featureFk = featureFk;
    }

    @XmlTransient
    public List<Qualifier> getQualifierList() {
        return qualifierList;
    }

    public void setQualifierList(List<Qualifier> qualifierList) {
        this.qualifierList = qualifierList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idFeatureKey != null ? idFeatureKey.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof FeatureKey)) {
            return false;
        }
        FeatureKey other = (FeatureKey) object;
        if ((this.idFeatureKey == null && other.idFeatureKey != null) || (this.idFeatureKey != null && !this.idFeatureKey.equals(other.idFeatureKey))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bio.jpa.entities.FeatureKey[ idFeatureKey=" + idFeatureKey + " ]";
    }

    @Override
    public int compareTo(FeatureKey f) {
        return getSeq().compareTo(f.getSeq());
    }
}
